using UnityEngine;
using UnityEngine.Events;

public class MonoController : MonoBehaviour
{
    private event UnityAction updateEvent;
    void Start()
    {
        //过场景不移除
        DontDestroyOnLoad(gameObject);
    }

    void Update()
    {
        if (updateEvent != null)
            updateEvent();
    }

    /// <summary>
    /// 添加帧更新事件函数
    /// </summary>
    /// <param name="fun"></param>
    public void AddUpdateListener(UnityAction fun)
    {
        updateEvent += fun;
    }

    /// <summary>
    /// 移除帧更新事件函数
    /// </summary>
    /// <param name="fun"></param>
    public void RemoveUpdateListener(UnityAction fun)
    {
        updateEvent -= fun;
    }
}
